<?php
/*
 * code to generate iCal file for project tasks
*/
//get the task details
$dueDate = $_GET['duedate'];
$subject = $_GET['subject'];

//format dates and UID
$UID = date("Ymd\THis\Z")."@nazz.co.uk";
$DTSTAMP = date("Ymd\THis\Z");

//create a UTC date for the start and end dates
$startDate = new DateTime($dueDate);
$endDate = new DateTime($dueDate);
$startDate->setTime(8,0,0);
$endDate->setTime(9,0,0);
$startDate->setTimezone(new DateTimeZone('UTC'));
$endDate->setTimezone(new DateTimeZone('UTC'));
//set start date
$DTSTART = $startDate->format('Ymd\THis\Z');
//set end date
$DTEND = $endDate->format('Ymd\THis\Z');
$SUMMARY = $subject;

//generate the iCal string
$iCal = "BEGIN:VCALENDAR
VERSION:2.0\n
PRODID:-//ACME Ltd//NONSGML Projects Database//EN
BEGIN:VEVENT
UID:{$UID}
DTSTAMP:{$DTSTAMP}
DTSTART:{$DTSTART}
DTEND:{$DTEND}
SUMMARY:{$SUMMARY}
END:VEVENT
END:VCALENDAR";

//return the iCal
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=taskevent.ics');
echo $iCal;
exit;
?>